Jump to content

PHP - elseif parse error

oskarha
Go to solution Solved by leodaniel,

Here are some errors I spotted quickly:

<?php
/* False else if, you forgot to close with a ) */
elseif ( empty($var) ) {}

/* You wrote */
elseif ( empty($var) /* ) is missing! */ {} 

 

I am currently working on a form that appends events to a text file used by a calendar on my website.
What I am struggling with is the PHP script which interprets the date variables from the form into a date for the events.txt file.

 

The script I have written gives this error when run:

Quote

Parse error: syntax error, unexpected '{' in /srv/disk13/2195185/www/thisismyshow.tk/calendar/append.php on line 19

The relevant code I am working with:

Spoiler

PHP script:


$startdate=$_REQUEST['startdate'];
$startmonth=$_REQUEST['startmonth'];
$startyear=$_REQUEST['startyear'];
$starttime1=$_REQUEST['starttime1'];
$starttime2=$_REQUEST['starttime2'];

if (empty($starttime1) AND empty($starttime2)) {
      $start="".$startyear."-".$startmonth."-".$startdate."";
   }  elseif (empty($starttime2) {
      $start="".$startyear."-".$startmonth."-".$startdate."T".$starttime1.""
   }  elseif (!empty($starttime2) {
      $start="".$startyear."-".$startmonth."-".$startdate."T".$starttime1."-".$starttime2.""
   }

HTML Form (extract):


<tr>
<td>Start</td>
<td>:</td>
<td>
<input name="startdate" type="text" id="startdate" size="1" required>
<font size="2" color="red">*</font>
<select name="startmonth" id="startmonth" required>
  <option value="01">January</option>
  <option value="02">February</option>
  <option value="03">March</option>
  <option value="04">April</option>
  <option value="05">May</option>
  <option value="06">June</option>
  <option value="07">July</option>
  <option value="08">August</option>
  <option value="09">September</option>
  <option value="10" selected>October</option>
  <option value="11">November</option>
  <option value="12">December</option>
</select>
<font size="2" color="red">*</font>
<select name="startyear" id="startyear" required>
  <option value="2017">2017</option>
  <option value="2018">2018</option>
  <option value="2019">2019</option>
  <option value="2020">2020</option>
</select>
<font size="2" color="red">*</font>
Time:
<input name="starttime1" type="text" id="starttime1" size="2">
-
<input name="starttime2" type="text" id="starttime2" size="2">
</td>
</tr>

I very new to PHP and HTML, any help is appreciated :)

[GUIDE] LGA 771 Mod for Dell Vostro 220 [GUIDE] LGA 775 BSEL Mod [BUILD] The Mighty Radeon-Powered Dell [VIDEO] Evolution of Intel CPUs

Can you game on an 8-year-old i7? Is the 4-year-old GTX 660 still relevant? Upgrading the HP Pro 3500

Main Rig:

Spoiler

CPU Intel Core i7 4930k @ 4.3GHz | Motherboard ASUS P9X79 Deluxe | RAM Hynix 32GB (8x4GB) 2133MHz CL11 | GPU Gigabyte GTX 980Ti G1 Gaming | Case NZXT Phantom 410 | Storage Samsung 850EVO 500GB, Seagate Barracuda 2TB | PSU Cooler Master G650M (650W) | Monitors x1 Dell U2515H, x2 Dell 1907FP | Cooling Noctua NH-D14 w. x2 NF-F12 iPPC-2000 PWM | Keyboard Logitech G610 ORION BROWN | Mouse Logitech Performance MX | OS Microsoft Windows 10 Pro x64

Link to comment
Share on other sites

Link to post
Share on other sites

check line 19 and look at ur syntax. provide everything between the php tags.

 

also i could rape ur shit sanitize all inputs. dont use a .txt file as a database

blackshades on

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Reece Leu said:

check line 19 and look at ur syntax. provide everything between the php tags.

 

also i could rape ur shit sanitize all inputs. dont use a .txt file as a database

Line 19 looks good to me, but i must be wrong.

Line 19 (look above for the surrounding lines):

   }  elseif (empty($starttime2) {

EDIT while typing: I forgot to close all of my brackets (im good at maths i should have seen this earlier >:()

What do you recommend me to use instead of a TXT? I tried JSON but it doesn't seem to play nicely with the norwegain æøå characters.

 

[GUIDE] LGA 771 Mod for Dell Vostro 220 [GUIDE] LGA 775 BSEL Mod [BUILD] The Mighty Radeon-Powered Dell [VIDEO] Evolution of Intel CPUs

Can you game on an 8-year-old i7? Is the 4-year-old GTX 660 still relevant? Upgrading the HP Pro 3500

Main Rig:

Spoiler

CPU Intel Core i7 4930k @ 4.3GHz | Motherboard ASUS P9X79 Deluxe | RAM Hynix 32GB (8x4GB) 2133MHz CL11 | GPU Gigabyte GTX 980Ti G1 Gaming | Case NZXT Phantom 410 | Storage Samsung 850EVO 500GB, Seagate Barracuda 2TB | PSU Cooler Master G650M (650W) | Monitors x1 Dell U2515H, x2 Dell 1907FP | Cooling Noctua NH-D14 w. x2 NF-F12 iPPC-2000 PWM | Keyboard Logitech G610 ORION BROWN | Mouse Logitech Performance MX | OS Microsoft Windows 10 Pro x64

Link to comment
Share on other sites

Link to post
Share on other sites

Here are some errors I spotted quickly:

<?php
/* False else if, you forgot to close with a ) */
elseif ( empty($var) ) {}

/* You wrote */
elseif ( empty($var) /* ) is missing! */ {} 

 

Business Management Student @ University St. Gallen (Switzerland)

HomeServer: i7 4930k - GTX 1070ti - ASUS Rampage IV Gene - 32Gb Ram

Laptop: MacBook Pro Retina 15" 2018

Operating Systems (Virtualised using VMware): Windows Pro 10, Cent OS 7

Occupation: Software Engineer

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, oskarha said:

Line 19 looks good to me, but i must be wrong.

Line 19 (look above for the surrounding lines):


   }  elseif (empty($starttime2) {

EDIT while typing: I forgot to close all of my brackets (im good at maths i should have seen this earlier >:()

What do you recommend me to use instead of a TXT? I tried JSON but it doesn't seem to play nicely with the norwegain æøå characters.

learn mysql + database management then use mariadb on linux to store

blackshades on

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, leodaniel said:

Here are some errors I spotted quickly:


<?php
/* False else if, you forgot to close with a ) */
elseif ( empty($var) ) {}

/* You wrote */
elseif ( empty($var) /* ) is missing! */ {} 

 

Thanks I realized, I fixed that now.

Now its complaining about an unexpected } on line 21:

   }  elseif (!empty($starttime2)) {

 

[GUIDE] LGA 771 Mod for Dell Vostro 220 [GUIDE] LGA 775 BSEL Mod [BUILD] The Mighty Radeon-Powered Dell [VIDEO] Evolution of Intel CPUs

Can you game on an 8-year-old i7? Is the 4-year-old GTX 660 still relevant? Upgrading the HP Pro 3500

Main Rig:

Spoiler

CPU Intel Core i7 4930k @ 4.3GHz | Motherboard ASUS P9X79 Deluxe | RAM Hynix 32GB (8x4GB) 2133MHz CL11 | GPU Gigabyte GTX 980Ti G1 Gaming | Case NZXT Phantom 410 | Storage Samsung 850EVO 500GB, Seagate Barracuda 2TB | PSU Cooler Master G650M (650W) | Monitors x1 Dell U2515H, x2 Dell 1907FP | Cooling Noctua NH-D14 w. x2 NF-F12 iPPC-2000 PWM | Keyboard Logitech G610 ORION BROWN | Mouse Logitech Performance MX | OS Microsoft Windows 10 Pro x64

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, oskarha said:

Thanks I realized, I fixed that now.

Now its complaining about an unexpected } on line 21:


   }  elseif (!empty($starttime2)) {

 

you forgot a

twice

Business Management Student @ University St. Gallen (Switzerland)

HomeServer: i7 4930k - GTX 1070ti - ASUS Rampage IV Gene - 32Gb Ram

Laptop: MacBook Pro Retina 15" 2018

Operating Systems (Virtualised using VMware): Windows Pro 10, Cent OS 7

Occupation: Software Engineer

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, leodaniel said:

you forgot a

twice

*intense face palm*

[GUIDE] LGA 771 Mod for Dell Vostro 220 [GUIDE] LGA 775 BSEL Mod [BUILD] The Mighty Radeon-Powered Dell [VIDEO] Evolution of Intel CPUs

Can you game on an 8-year-old i7? Is the 4-year-old GTX 660 still relevant? Upgrading the HP Pro 3500

Main Rig:

Spoiler

CPU Intel Core i7 4930k @ 4.3GHz | Motherboard ASUS P9X79 Deluxe | RAM Hynix 32GB (8x4GB) 2133MHz CL11 | GPU Gigabyte GTX 980Ti G1 Gaming | Case NZXT Phantom 410 | Storage Samsung 850EVO 500GB, Seagate Barracuda 2TB | PSU Cooler Master G650M (650W) | Monitors x1 Dell U2515H, x2 Dell 1907FP | Cooling Noctua NH-D14 w. x2 NF-F12 iPPC-2000 PWM | Keyboard Logitech G610 ORION BROWN | Mouse Logitech Performance MX | OS Microsoft Windows 10 Pro x64

Link to comment
Share on other sites

Link to post
Share on other sites

Ok, I think I was able to fix the problem, the form seems to work perfectly :D

[GUIDE] LGA 771 Mod for Dell Vostro 220 [GUIDE] LGA 775 BSEL Mod [BUILD] The Mighty Radeon-Powered Dell [VIDEO] Evolution of Intel CPUs

Can you game on an 8-year-old i7? Is the 4-year-old GTX 660 still relevant? Upgrading the HP Pro 3500

Main Rig:

Spoiler

CPU Intel Core i7 4930k @ 4.3GHz | Motherboard ASUS P9X79 Deluxe | RAM Hynix 32GB (8x4GB) 2133MHz CL11 | GPU Gigabyte GTX 980Ti G1 Gaming | Case NZXT Phantom 410 | Storage Samsung 850EVO 500GB, Seagate Barracuda 2TB | PSU Cooler Master G650M (650W) | Monitors x1 Dell U2515H, x2 Dell 1907FP | Cooling Noctua NH-D14 w. x2 NF-F12 iPPC-2000 PWM | Keyboard Logitech G610 ORION BROWN | Mouse Logitech Performance MX | OS Microsoft Windows 10 Pro x64

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×