grahamb314 Posted September 14, 2008 Share Posted September 14, 2008 The following code is supposed to insert some data from the previous page into the database. It doesnt show any errors and no data goes into the database!? Any Quote <?php require_once 'mysql_connect.php'; $query = "SELECT * FROM `grahamb_test`.`schedule` WHERE `Show` = '{ $_POST["Show"]}';"; $result = mysqli_query($mysqli, $query) or die("Query:{$query} <br>Error:".mysqli_error($mysqli)); echo "rows = ".mysqli_num_rows($result); if (mysqli_num_rows($result) >= 1) { echo "This show name already exists"; } else { $sql = mysqli_query($mysqli, "INSERT INTO `grahamb_test`.`schedule` (`ID`, `Show`, `StartTime`, `EndTime`, `Day`, `Type`, `Page`, `Profile_url` ) VALUES (NULL,'".$_POST["Show"]."','".$_POST["StartTime"]."','".$_POST["EndTime"]."''".$_POST["Day"]."','".$_POST["Type"]."','".$_POST["Page"]."','".$_POST["Profile_url"]."')"); echo "<p>The show <b> ". $_POST["Show"] ." </b>has been added to the database!"; } ?> Link to comment https://forums.phpfreaks.com/topic/124224-solved-php-and-sql-problem/ Share on other sites More sharing options...
Mchl Posted September 14, 2008 Share Posted September 14, 2008 Do you have error_reporting enabled? Link to comment https://forums.phpfreaks.com/topic/124224-solved-php-and-sql-problem/#findComment-641464 Share on other sites More sharing options...
grahamb314 Posted September 14, 2008 Author Share Posted September 14, 2008 Yep! Thats whats so odd about it - Why wont it write it in? - Have I done something silly? Link to comment https://forums.phpfreaks.com/topic/124224-solved-php-and-sql-problem/#findComment-641465 Share on other sites More sharing options...
Mchl Posted September 14, 2008 Share Posted September 14, 2008 Add or die("Query:{$query} Error:".mysqli_error($mysqli)); to $sql = mysqli_query($mysqli, "INSERT INTO `grahamb_test`.`schedule` (`ID`, `Show`, `StartTime`, `EndTime`, `Day`, `Type`, `Page`, `Profile_url` ) VALUES (NULL,'".$_POST["Show"]."','".$_POST["StartTime"]."','".$_POST["EndTime"]."''".$_POST["Day"]."','".$_POST["Type"]."','".$_POST["Page"]."','".$_POST["Profile_url"]."')"); That would tell you have a missing comma here $_POST["EndTime"]."''".$_POST["Day"]. You could actually write this query like this: $sql = mysqli_query($mysqli, "INSERT INTO `grahamb_test`.`schedule` ( `Show`, `StartTime`, `EndTime`, `Day`, `Type`, `Page`, `Profile_url` ) VALUES ('{$_POST["Show"]}','{$_POST["StartTime"]}','{$_POST["EndTime"]}','{$_POST["Day"]}','{$_POST["Type"]}','{$_POST["Page"]}','{$_POST["Profile_url"]}')"); Link to comment https://forums.phpfreaks.com/topic/124224-solved-php-and-sql-problem/#findComment-641474 Share on other sites More sharing options...
burn1337 Posted September 14, 2008 Share Posted September 14, 2008 try : require('mysql_connect.php'); Link to comment https://forums.phpfreaks.com/topic/124224-solved-php-and-sql-problem/#findComment-641475 Share on other sites More sharing options...
Mchl Posted September 14, 2008 Share Posted September 14, 2008 require() doesn't require () Link to comment https://forums.phpfreaks.com/topic/124224-solved-php-and-sql-problem/#findComment-641478 Share on other sites More sharing options...
grahamb314 Posted September 14, 2008 Author Share Posted September 14, 2008 Youve lost me! Link to comment https://forums.phpfreaks.com/topic/124224-solved-php-and-sql-problem/#findComment-641479 Share on other sites More sharing options...
Adam Posted September 14, 2008 Share Posted September 14, 2008 Think Mchl has it! Reckon you might want to look into some security aswell by the way! Adam Link to comment https://forums.phpfreaks.com/topic/124224-solved-php-and-sql-problem/#findComment-641480 Share on other sites More sharing options...
Mchl Posted September 14, 2008 Share Posted September 14, 2008 Sorry There's a missing comma in your second query between $_POST['EndTime'] and $_POST['Day'] Link to comment https://forums.phpfreaks.com/topic/124224-solved-php-and-sql-problem/#findComment-641481 Share on other sites More sharing options...
grahamb314 Posted September 14, 2008 Author Share Posted September 14, 2008 Oh I understand! Thank you all so much, All working now Link to comment https://forums.phpfreaks.com/topic/124224-solved-php-and-sql-problem/#findComment-641482 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.