MySQL Forums
Forum List  »  PHP

adding data to mysql table using php code
Posted by: John carey
Date: November 17, 2021 10:02PM

note sure whats wrong with this code. Able to connect to database. able to add record in program hardcode.

<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>quickinfo3</TITLE>
<style>
input[type=text] {
width: 30%;
padding: 7px ;
margin: 5px 0;
border: 1px solid #000000;
}
input[type=submit] {
width: 30%;
padding: 9px;
margin: 5px 0;

border: 2px solid #000000;
outline: none;
background-color:green;
color:white;
}
</style>
<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
</HEAD>
<BODY bgcolor="lightyellow">
<form action="" method="post" name="quickform">
<font face="comic sans ms" font size=6><u>Quick Survey</u></font>
<br>
<br>
<!--<label>id:</label><input type="text" name="id" size=11 maxlength=10><br>-->
<label>custid:</label><input type="text" name="custidnbr" size=10><br>
<label>Name:</label><input type="text" name="name1" size=35><br>
Would you like a call back?<input type="checkbox" name="callback"><br>
<label>phone number:</label><input type="text" name="phone" size=14><br>
Would you like information sent to you by email?<input type="checkbox" name="sendemail"><br>
<label>email address is?:<input type="text" name="emailaddr" size=35><br>
What can we do to make this webpage better?<br> <textarea name="bettertexta1" rows="6" cols="60"></textarea><br>
Comments(Suggestions/Complaints/Opinions/Other)?<br> <textarea name="commentstexta2" rows="6" cols="60"></textarea><br>
<input type="submit" name="submit" value="submit"><br><input type="reset" value="reset">
<span style='font-size:12.0pt'><input type="button" value="close" onclick="window.close();"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button type="button"
onclick="history.back();">Go Back a page</button>
<button type="button"
onclick="history.forward();">Go Forward a page</button>

</form>
</BODY>
</HTML>
<!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->

<?php
$server = "db5005776933.hosting-data.io";
$username = "dbu798462";
$password = "9211Survey2^";
$dbname = "dbs4859761";

$conn = mysqli_connect($server, $username, $password, $dbname);
if(isset($_post['submit'])){

if(!empty($_post['custidnbr']) && !empty($_post['name1']) && !empty($_post['callback']) && !empty($_post['phone']) && !empty($_post['sendemail']) && !empty($_post['emailaddr'])
&& !empty($_post['bettertexta1']) && !empty($_post['commentstexta2'])){

//$id = $_post['id'];
$custidnbr = $_POST['custidnbr'];
$name1 = $_POST['name1'];
$callback = $_POST['callback'];
$phone = $_POST['phone'];
$sendemail = $_POST['sendemail'];
$emailaddr = $_POST['emailaddr'];
$bettertexta1 = $_POST['bettertexta1'];
$commentstexta2 = $_POST['commentstexta2'];

$query = "insert into quickform(custidnbr,name1,callback,phone,sendemail,emailaddr,bettertexta1,commentstexta2)
values('$custidnbr','$name1','$callback','$phone','$sendemail','$emailaddr','$bettertexta1','$commentstexta2')";

//values('100008','amie','n','8135459496','n','carey@gmail.com','lets','go')";
//values('100008', 'john jr','n','813-545-9496','n','carey@gmail.com','music','cars')";


$run = mysqli_query($conn,$query) or die(mysqli_error());

if($run){
echo "form submitted successfully";
}else{
echo "form not submitted";
}
}else{
echo "all fields required";
}
}
?>

Options: ReplyQuote


Subject
Written By
Posted
adding data to mysql table using php code
November 17, 2021 10:02PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.