Jump to content

Call To Undefined Function Mysql_Connect() Revisited....


ack

Recommended Posts

I went to the link indicated in the forum post in my title and got 404 errors!

 

That said, here is my nube problem:

 

I have an form page that loads a PHP app in a frame which displays a list of date information from a table. The idea being as the user fills out the form he/she can refer to the list of dates to avoid "double-booking".

 

Once the form has been filled out and the ever-popular "submit" button is clicked, a PHP page is executed that is suposed to take the information gathered and put it into a record in the SAME table that the php app in the form page's frame used.

 

Before adding this PHP app to the form page, everything worked fine.

 

Now I get a "couldn't select database" error - which is the "die" message found in this code:

 

$db = mysql_select_db($database,$connection)

or die ("Couldn't select database");

 

...when the php app that receives the form data tries to connect to the database.

 

I do close the database in the list applet and I have also tried the same process with the database remaining open when the "submit" button with the same results.

 

What am I missing here? Must I somehow close the php ap in the frame as part of the process of passing data to the following pgp app?

 

Is there a way to set up the database so that, once opened, subsequent php apps can modify the table?

 

Your assistance is much appreciated.

Link to comment
Share on other sites

Here is my code (abbreviated a bit for clarity AND):

 

The Submit form:

 

<?php
session_start();
?>

<html>
<head>
<title>Radio Remote Event Booking Input></title>
</head>

<?php
 /*$_SESSION['session_var'] = "BODY";*/


$frmyear = date("Y");    // 10, 3, 2001
$frmday = date("d");    // 10, 3, 2001
$frmmonth = date("m");    // 10, 3, 2001
echo "

<FORM ACTION='saverrsdata.php' method='POST'>

<h5>
<table border = '0'>

<tr>
<th colspan = '4'>
<img src='redBannerPhone.png' ALIGN = 'left'  border='0' usemap='#REMOTERADIO'/>
</th>
</TR>
<tr>

<TD><b>Enter Station Call letters:</b></TD>
<TD> <INPUT TYPE='text' name='instation' VALUE='KFKF-FM' maxlength = '7' size = '7'></TD>
<TD rowspan = '7'><img src='transitwebani.gif'align = 'right' height ='200' width='400'></TD>

</TR>
<TR>
<TD><b>Enter Account Executive Name:</b></TD>
<TD> <INPUT TYPE='text' name='inacctexec' VALUE='Bob Ferapples' maxlength = '15' size = '15'></TD>
</TR>
<TR>
<TD><B> A/E Telephone Number:</B></TD>
<TD><B><INPUT TYPE ='TEXT' NAME='inaephone' VALUE='816-555-1212' maxlength -'10' size ='14'></td>
</TR>
<TR>
<TD><B> A/E Email Address:</B></TD>
<TD><B><INPUT TYPE ='TEXT' NAME='inaeemail' VALUE='acker_dackerly@yahoo.com' maxlength -'30' size ='30'></td>
</TR>
<TR>

<TD><b>Enter Client's Business Name:</b></TD><TD><INPUT TYPE='text' name='inclient' VALUE='Bill's Pajama Bottoms' maxlength = '25' size = '25'></TD>
</TR>
<TR>
<TD><B> Client Telephone Number:</B></TD>
<TD><B><INPUT TYPE ='TEXT' NAME='inclientphone' VALUE='816-223-1122' maxlength -'10' size ='14'></td>
</TR>
<TR>
<TD><b>Enter Address:</b></TD><TD> <INPUT TYPE='text' name='inaddress' VALUE='1000 Missouri ave' maxlength = '25' size = '25'></TD>
</TR>
<TR>
<TD><b>Enter City:</b></TD><TD>   <INPUT TYPE='text' name='incity' VALUE='Kansas City' maxlength = '15' size = '15'></TD>
  <TD rowspan = '6' align= 'center'><img src='prize_machine_bg.gif' height = '200' width = '200'></TD>
</TR>
<TR>
<TD><b>Enter State:</b></TD>
<TD> 
<select NAME ='instate' maxlength = '2' >
<OPTION SELECTED>KS
<OPTION>MO
</SELECT><BR>
</TD>
</TR>


<TR>
<TD><b>Enter ZIPCode:</b></TD><TD><INPUT TYPE='text' name='inzip' VALUE='64110' maxlength = '10' size = '10'></TD>
</TR>
<TR>
<TD><b>Enter Client's Contact Name:</b></TD><TD>   <INPUT TYPE='text' name='incontact' VALUE='Bill Glass' maxlength = '15' size = '15'></TD>
</TR>
<TR>
<TD><b>Enter Producer's Name:</b></TD><TD>  <INPUT TYPE='text' name='inproducer' VALUE='Jim Cambron' maxlength = '15' size = '15'></TD>
</TR>
<TR>
  <TD><b>Enter Talent's Name:</b></TD><TD>  <INPUT TYPE='text' name='intalent' VALUE='Charles DeTuna' maxlength = '15' size = '15'></TD>
</TR>
<TR>
  <TD><b>Enter Notes Here:</b></TD><TD><TEXTAREA name='innotes' rows='10' cols='32' VALUE='blah blah blah!' > </TEXTAREA></TD>
  <TD valign = 'bottom'><B><h3> <font color='red'>Previously Booked Event List<BR>   Check below for booking conflicts!</font></H3></B></TD>
</TR>

<TR>
<TD><b>Enter Date of Broadcast Year:</b></TD>
<TD> 
<select NAME ='inyear' maxlength = '4' >
<OPTION SELECTED> $frmyear
<OPTION>2013
......
......
......
</SELECT><BR>
</TD>


/* here is where the form program loads eventlist....   */


<td rowspan='5'>
<iframe src='eventlist.php' height='160' width='400'>
 <p>Your browser does not support iframes.</p>
</iframe>
<TD>

</TR>

<TR>
<TD><b>Enter Date of Broadcast Month:</b></TD>
<TD> 
<select NAME ='inmonth' maxlength = '2' >
<OPTION SELECTED> $frmmonth
<OPTION>02
......
......
......
</SELECT><BR>
</TD>
</TR>

<TR>
<TD><b>Enter Date of Broadcast Day:</b></TD>
<TD> 
<select NAME ='inday' maxlength = '2' >
<OPTION SELECTED>  $frmday
<OPTION>02
......
......
......
</SELECT><BR>
</TD>
</TR>

<TR>
<TD><b>Enter Start Time:</b> </TD>
<TD>

<select NAME ='instart' maxlength = '7' >
<OPTION SELECTED>06:00AM
<OPTION>07:00AM
......
......
......
</SELECT><BR>

</TD>
</TR>
<TR>
<TD><b>Enter End Time:</b> </TD>

<TD>
<select NAME ='inend' maxlength = '5' >
<OPTION selected>07:00AM
<OPTION>07:00AM
......
......
......
</SELECT><BR>
</TD>
</TR>
</table>

</h5>


<P><b><i>Submit</i> data:</b>
<input type='submit' value='Submit'> </P></h4>
</form>";
?>

 

The "lookup PHP app called "eventlist.php"....

(this is the first time the database is opened in the program flow...)

 

<?php
/* savenewdata.php
* by Jim Cambron
* a revised version of:
*
* Program: petDisplay.php
* Desc: Displays all pets in selected category.
*
* Source: "PHP and Mysql for Dummies" by Janet Valade
*/

 session_start();


?>

<body background="RRS_bkgd_blu.jpg" style='tab-interval:.5in'>
<BASEFONT FACE="Arial, Helvetica, Geneva, sans-serif">



<map name='REMOTERADIO'>
 <area shape='RECT' coords='10,67,60,80' href='index.htm' alt='Home'/>
 <area shape='RECT' coords='120,67,225,80' href='RRSinput.php' alt='Enter Event'/>
 <area shape='RECT' coords='289,67,478,80' href='lookup.php' alt='View Scheduled Events'/>
</map>

<img src='redBannerPhone.png' ALIGN = 'left'  border='0' usemap='#REMOTERADIO'/>

<img src ='prize_machine_bg.gif' height = "200" width = "200" align= 'right'><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>


<img src='transitwebani.gif'align = 'right' height ='200' width='400'>

<h3><b>List of Current Bookings:</b></h3>
(Use this list to avoid double-booking a timeslot)<BR><BR>

<!-- access the table -->



<?php
/* put today's date into a variable
  so that only future bookings are listed   */


$tyear =date(Y);
$tmonth = date(m);
$tday = date(d);
$thisday = $tyear." ".$tmonth."-".$tday;

echo"today's date:".$thisday."<BR>";
/* Open the database  */

 $host="somewhere.com";
 $user="88888888888";
 $password="999999999";
 $database = "22222222222";
 $connection = mysql_connect($host,$user,$password)
  or die ("couldn't connect to server");
 $db = mysql_select_db($database,$connection)
  or die ("Couldn't select database");



/* display everything   */
 $query = "SELECT * FROM remoteraio order by starttime";


/* run the query */
$result = mysql_query($query)
  or die ("Couldn't execute query.");


echo "<table border='3' cellpadding = '5'>

<TR>
<TD>Start time</TD>
<TD>End Time</TD></TR>
";


while ($row = mysql_fetch_array($result))
 {

  /* extract the contents of the row */
 extract($row);

  /*  is $starttime less than $thisday?  */

 $val = strncmp($starttime,$thisday,10);
 If ($val == 0) echo"<TD>",$starttime,"</TD><TD>",$endtime,"</TD></TR>";
 If ($val > 0) echo"<TD>",$starttime,"</TD><TD>",$endtime,"</TD></TR>";

 /* display information

echo"<TD>",$starttime,"</TD>";
echo"<TD>",$endtime,"</TD></TR>";  */
 }

msql_close($connection);


?> 
</TR>
</body>
</html>

 

The save data php app called "saverrsdata.php....

 

<?php
/*
******************************************************************************************
* savenewdata.php
* by Jim Cambron
* a revised version of:
*
* Program: petDisplay.php
* Desc: Displays all pets in selected category.
*
* Source: "PHP and Mysql for Dummies" by Janet Valade
*
*
*  Modified 12-11-12
* this version contains only code to store a remote radio database record, display the results and finally send as an email.
* J Cambron
*
******************************************************************************************
*/

 session_start();


?>

<STYLE TYPE="text/css">
<!--
H4
  {
  color:black;
  font-size:10pt;
  font-weight:400;
  }
-->
</STYLE TYPE="text/css">
<!--
H5
  {
  color:black;
  font-size:7pt;
  font-weight:600;
  }
-->
</STYLE>

<STYLE TYPE="text/css">
<!--
H3
  {
  color:black;
  font-size:12pt;
  font-weight:800;
  }
-->
</STYLE>

<body background="RRS_bkgd_blu.jpg" style='tab-interval:.5in'>
<BASEFONT FACE="Arial, Helvetica, Geneva, sans-serif">

<map name='REMOTERADIO'>
 <area shape='RECT' coords='10,67,60,80' href='index.htm' alt='Home'/>
 <area shape='RECT' coords='120,67,225,80' href='RRSinput.php' alt='Enter Event'/>
 <area shape='RECT' coords='289,67,478,80' href='lookup.php' alt='View Scheduled Events'/>
</map>

<img src='redBannerPhone.png' ALIGN = 'left'  border='0' usemap='#REMOTERADIO'/>

<img src ='prize_machine_bg.gif' height = "200" width = "200" align= 'right'><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>


<img src='transitwebani.gif'align = 'right' height ='200' width='400'>
<h5>


<!-- access the table -->



<?php


/* get today's date */




ini_set('display_errors', 'On');
error_reporting(E_ALL);



/* Open the database  */

 $host="somewhere.com";
 $user="888888888888888";
 $password="9999999999999999";
 $database = "2222222222";
 $connection = mysql_connect($host,$user,$password)
  or die ("couldn't connect to server");
 $db = mysql_select_db($database,$connection)
  or die ("Couldn't select database");





/* grab the values entered  */

$instation = $_POST['instation'];
$inacctexec = $_POST['inacctexec'];
$inaephone = $_POST['inaephone'];
$inaeemail = $_POST['inaeemail'];
$inclient = $_POST['inclient'];
$inclientphone = $_POST['inclientphone'];
$inaddress = $_POST['inaddress'];
$incity = $_POST['incity'];
$instate = $_POST['instate'];
$inzip = $_POST['inzip'];
$incontact = $_POST['incontact'];
$inyear = $_POST['inyear'];
$inmonth = $_POST['inmonth'];
$inday = $_POST['inday'];
$instart = $_POST['instart'];
$inend = $_POST['inend'];
$inproducer = $_POST['inproducer'];
$intalent = $_POST['intalent'];
$innotes = $_POST['innotes'];





/* create start and end times variables...  */

$starttim = $inmonth."/".$inday."/".$inyear." ".$instart;

$endtime = $inmonth."/".$inday."/".$inyear." ".$inend;


$today = date("m/d/y"); // 03.10.01





/* Get the next id-no value by simply using the number of records value
  as it will be exactly the next available number in sequence because
  the id_no value starts with 0 for the first record.  */

$query = "SELECT ALL * FROM remoteraio";

$result = mysql_query($query) or die(mysql_error());
$injobno = mysql_num_rows($result);
++$injobno;




/* let's check the $pstarttime to see if there is an existing event in the database */

while ($row = mysql_fetch_array($result))
 {

/* -- extract the contents of the row -- */

 extract($row);


/* ---find a match? if so exit script with message --- */
 if ($starttim == $starttime){
 exit("<h3><b>There is already an event scheduled for this day and time! <BR><BR>Click <i>Book Event</i> again and select another event day/time.</b></h3>");
}
 }





/* Put the data into the database */

$query= "INSERT INTO remoteraio(jobno,station,acctexec,aephone,aeemail,client,clientphone,address,city,state,zip,contact,starttime,endtime,producer,talent,notes,entrydate) VALUES ('$injobno','$instation','$inacctexec','$inaephone','$inaeemail','$inclient','$inclientphone','$inaddress','$incity','$instate','$inzip','$incontact','$starttim','$endtime','$inproducer','$intalent','$innotes','$today')" ;
$result = mysql_query($query) or die ("Couldn't select database");


/* close the connection to remoteraio */

/* mysql_close($result);*/


/* calendar database processing goes here....*/

/*  first, generate a julian number from $inmonth $inday and $inyear. */

$d=cal_to_jd(CAL_GREGORIAN,$inmonth,$inday,$inyear);


echo "the julian number is:".$d."<BR>";



/* next convert the start time to 24 hour notation with trailing seconds (:00) */

$ampm = substr($instart, -2);   // returns "AM or PM"
$minutes = substr($instart,-4,2);  // returns minutes
$hours = substr($instart,-7,2); // returns hours
$chkpmval = 12;
if ($ampm == "PM") {
if ($hours < $chkpmval) {
$hours = $hours + $chkpmval;
}
  }
  $cal_starttime = $hours.":".$minutes.":00";

echo "start time :".$cal_starttime."<BR>";


/* next, convert the start time to 24 hour notation with trailing seconds (:00) */

$ampm = substr($inend, -2);   // returns "AM or PM"
$minutes = substr($inend,-4,2);  // returns minutes
$hours = substr($inend,-7,2); // returns hours
$chkpmval = 12;
if ($ampm == "PM") {
if ($hours < $chkpmval) {
$hours = $hours + $chkpmval;
}
  }
  $cal_endtime = $hours.":".$minutes.":00";


echo "end time: ".$cal_endtime."<BR>";


/* FINALLY, STORE THE DATA INTO THE CALENDAR TABLE!  */

$query= "INSERT INTO epc7_calendar(startDate,endDate,startTime, endTime,title,descr) VALUES ('$d','$d','$cal_starttime','$cal_endtime','$inclient','$innotes')" ;
$result = mysql_query($query) or die ("Couldn't select database");


/* close the table  */

mysql_close();


/* BUILD A PAGE THAT SHOWS what has been entered */
echo "

<h3><b>This is what you just booked:</b></h3>

<b>Station Call letters:</b>$instation <BR>
<b>Enter Account Executive Name:</b> $inacctexec <BR>
<B> A/E Telephone Number:</B>$inaephone <BR>
<B> A/E Email:</B> $inaeemail <BR>
<B> Client Name:</B> $inclient <BR>
<B>Client phone number:</B> $inclientphone <BR>
<B>address:</B> $inaddress <BR>
<B>city:</B> $incity <BR>
<B>State:</B> $instate <B>ZIP:</B> $inzip <BR>
<B>Contact:</B> $incontact <BR>
<B>Date:</B>  $inmonth/$inday/$inyear <BR>
<B>Start Time:</B> $starttime <BR>
<B>End Time:</B> $endtime <BR>
<B>Producer:</B> $inproducer <BR>
<B>Talent:</B> $intalent <BR>
<B>Comments:</B> $innotes <BR>";




/* SEND EVERYTHING AS AN EMAIL TO CLIENT EMAIL AND TO RRS */

$to = $inaeemail;
$subject = "Remote Radio Services Booking";
$mess ="Station:\r\n $instation\r\n\r\n Booking Date/Time:\r\n $inmonth $inday $inyear $instart to $endtime \r\n\r\n Account Executive:\r\n $inacctexec  $inaephone \r\n\r\n Client Info:\r\n $inclient \r\n $inclientphone \r\n $inaddress \r\n $incity, $instate $inzip \r\n\r\n Contact: $incontact \r\n Producer: $inproducer \r\n Talent: $intalent \r\n\r\n Notes, Script:\r\n $innotes" ;
$headers = "bcc:noneofyourbeezwax@mail.com\r\n";
$mailsend = mail($to,$subject,$mess,$headers);

?> 

<BR>A copy of this booking has been sent to the above Account Executive's email address and to Remote Radio Services' email account.
</body>
</html>

 

The End....

Edited by PFMaBiSmAd
added code tags
Link to comment
Share on other sites

In your code, you use the die("Couldn't select database") call after a couple of INSERT statements as well. Are you sure it is not one of them that is failing? You should display the mysql_error in the die message, since mysql will tell you why the call failed.

 

die("Insert Failed: $query: " . mysql_error());
#
# OR
#
die("Couldn't select database: " . mysql_error());

or something along those lines.

 

Oh, and use code tags

 ... 

around any code you post, it makes it a lot easier to read.

Link to comment
Share on other sites

In your code, you use the die("Couldn't select database") call after a couple of INSERT statements as well. Are you sure it is not one of them that is failing? You should display the mysql_error in the die message, since mysql will tell you why the call failed.

 

die("Insert Failed: $query: " . mysql_error());
#
# OR
#
die("Couldn't select database: " . mysql_error());

or something along those lines.

 

Oh, and use code tags __CODEBOX_0__ around any code you post, it makes it a lot easier to read.

 

 

Thank you, DavidAM!

 

My debugging skills need much work!

 

I plugged in mysql_error() and Voila! I got some information back!

 

In this case, it was "Duplicate entry '5' for key 1"

 

I am not exactly sure what that means, but I suspect I have some sort of mismatch between the variable fields and the table fields in a query. Or perhaps I have inadvertantly placed a too-long string into the table field...

 

Does that make sense?

 

Thank you very much for the debugging help! I'll try not to forget it....

Edited by ack
Link to comment
Share on other sites

Yay! figured out the problem thanks to Muddy_Funster!

 

At some time I had deleted test records in a fashion that left 4 test records - one of which had a key field containing the value "5".

 

Every time I created a new record, it put "5" in the key field and tried to save the record with a duplicate key record.

 

I need to be careful about mucking with the table outside of the application....

 

Again, thanks all!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.